#include "libmri.h"
#include "auxfns.h"

void plan_wavelet (int &nc, int &lf,  int &L, int *&S,
                   float *&lor, float *&hir, float *&lod, float *&hid,
                   cplxf *X, int m, int n)
{
	int dsize[4] = {1, m, n, 1};
	int *nzmask; sampling_pattern (nzmask, X, dsize);

	int csize[2]; calib_size (csize[0], csize[1], nzmask, m, n);

	int m0 = m, L0 = 0, n0 = n, L1 = 0;

	while (m0 > 0){ ++L0; m0 >>= 1; }
	while (n0 > 0){ ++L1; n0 >>= 1; }

	L = (L0 < L1) ? L0 : L1;

	float *filters;
	lf = get_wavelet_filters (filters);

	lod = filters + 0*lf;
	hid = filters + 1*lf;
	lor = filters + 2*lf;
	hir = filters + 3*lf;

	S=0; nc = wavelet_sizes (S, m, n, L, lf);

	while (S[0] < csize[0] || S[1] < csize[1])
		 nc = wavelet_sizes (S, m, n, --L, lf);

	delete [] nzmask;
}

void destroy_wavelet (float *lor, int *S){
	delete [] lor;
	delete [] S;
}

